﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Reflection;

namespace MoqContrib.AutoMock.Tests.Conventions
{
	/// <summary>
	/// All of these tests just ensure consistency between interface and implementors
	/// </summary>
	[TestFixture]
	class Between_IMocker_and_AutoMockHelper
	{
		/// <summary>
		/// Test that for each member in IAutoMocker, each corresponding
		/// member in AutoMockHelper has the same members that are marked 
		/// obsolete
		/// </summary>
		[Test]
		public void Obsolete_attributes_match()
		{
			var @interface = typeof(IAutoMocker).GetMembers()
				.Select(x => new 
				{
					x.Name, 
					Attributes=x.GetCustomAttributes(typeof(ObsoleteAttribute), false) 
				})
				.Where(x => x.Attributes.Any()).ToList();
			var @class = typeof(AutoMockHelper).GetMembers()
				.Where(x => @interface.Any(y => y.Name == x.Name))
				.Select(x => new
				{
					x.Name,
					Attributes=x.GetCustomAttributes(typeof(ObsoleteAttribute), false)
				})
				.Where(x => x.Attributes.Any()).ToList();

			Assert.That(@class.Select(x => x.Name),
				Is.EquivalentTo(@interface.Select(x => x.Name)));
			Assert.That(@class.Select(x => x.Attributes),
				Is.EquivalentTo(@interface.Select(x => x.Attributes)));
		}
	}
}
